# Maintainer: Marko Käning <mk-lists@mailbox.org>

_realname=bsdfprocessor
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.1
pkgrel=3
epoch=
pkgdesc="Application for displaying and editing of BSDF files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/KimuraRyo/BSDFProcessor'
license=('spdx:MPL-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-libbsdf")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-OpenSceneGraph"
         "${MINGW_PACKAGE_PREFIX}-osgQt"
         $([[ ${MINGW_PACKAGE_PREFIX} != *-clang-* ]] || echo "${MINGW_PACKAGE_PREFIX}-openmp"))
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/KimuraRyo/${_realname}/archive/v${pkgver}.tar.gz"
        'optimisations-CMakeLists.txt.patch')
sha256sums=('5f9325fa887d275453bddbb18c4b794fe0ce83bb439fa486f687c468bf27c4f4'
            '55c03bbbf2b790c0aaa71f1b8638de1145c709b2ec251398acc4aef1d28121bc')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np0 -i "${srcdir}/optimisations-CMakeLists.txt.patch"
}

build() {
  [[ -d build-${MSYSTEM} ]] && rm -rf build-${MSYSTEM}
  mkdir build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DEIGEN3_INCLUDE_DIR=${MINGW_PREFIX}/include/eigen3 \
    -DLIBBSDF_DIR=${MINGW_PREFIX}/include/libbsdf \
    -DCMAKE_CXX_STANDARD=11 \
    ../${_realname}-${pkgver}

  cmake --build .
}

package() {
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  cp -f "${srcdir}"/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  cp -f "${srcdir}"/build-${MSYSTEM}/BSDFProcessor.exe ${pkgdir}${MINGW_PREFIX}/bin/bsdfprocessor.exe
}
